package com.junsi.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.junsi.bean.Distribution;
import com.junsi.mapper.DistributionMapper;
import com.junsi.service.DistributionSerivce;

/**
 * 权限分配Serivce接口实现类
 * @author Administrator
 *
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class DistributionSerivceImpl implements DistributionSerivce {

	@Autowired
	private DistributionMapper distributionMapper;
	
	@Override
	public Distribution findById(Integer id) {
		
		return distributionMapper.findById(id);
	}

	@Override
	public List<Distribution> findByAll() {
		
		return distributionMapper.findByAll();
	}

	@Override
	public boolean save(Distribution distribution) {
		int i = distributionMapper.save(distribution);
		if(i == 1){
			return true;
		}
		return false;
	}

	@Override
	public boolean update(Distribution distribution) {
		int i = distributionMapper.update(distribution);
		if(i == 1){
			return true;
		}
		return false;
	}

	@Override
	public boolean delete(Integer id) {
		int i = distributionMapper.delete(id);
		if(i == 1){
			return true;
		}
		return false;
	}

	@Override
	public Distribution findByStaffId(Integer staffId) {
		
		return distributionMapper.findByStaffId(staffId);
	}

	@Override
	public boolean updateDistribution(Integer role_id, List<Integer> staff_id) {
		
		if(role_id == null){
			return false;
		}
		if(staff_id.size()==0){
			return false;
		}
		for (Integer integer : staff_id) {
			int i = distributionMapper.updateDistribution(role_id, integer);
			if(i == 0){
				return false;
			}
		}
		
		return true;
	}

	@Override
	public boolean updateByStrffId(Distribution distribution) {
		int i = distributionMapper.updateByStrffId(distribution);
		if(i == 1){
			return true;
		}
		return false;
	}


}
